f = open('键盘输入.txt',mode='a',encoding='utf-8')

while True:
    s = input("请输入:\n")
    if s=='#':
        break 
    f.write(s)
    f.write("\n")  
    # 刷新
    f.flush() 

#关闭文件
f.close()

